local zishucup__buqun = fk.CreateSkill{
  name = "zishucup__buqun",
}

Fk:loadTranslationTable{
  ["zishucup__buqun"] = "不群",
  [":zishucup__buqun"] = "结束阶段，你可以摸一张牌并重复至手牌数全场唯一。你使用牌时，须将一名手牌数与你相同的角色一张牌移出游戏至回合结束。",

  ["$zishucup__buqun"] = "不群",
  ["#zishucup__buqun-choose"] = "不群：请选择一名手牌数等于你的角色，将其一张牌本回合移出游戏",

  ["$zishucup__buqun1"] = " ",
  ["$zishucup__buqun2"] = " ",
}

zishucup__buqun:addEffect(fk.EventPhaseStart, {
  anim_type = "drawcard",
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(zishucup__buqun.name) and player.phase == Player.Finish
  end,
  on_use = function(self, event, target, player, data)
    while not player.dead do
      player:drawCards(1, zishucup__buqun.name)
      if not table.find(player.room:getOtherPlayers(player), function(p) return p:getHandcardNum() == player:getHandcardNum() end) then
        break
      end
    end
  end,
})

zishucup__buqun:addEffect(fk.CardUsing, {
  anim_type = "control",
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(zishucup__buqun.name) and table.find(player.room:getAllPlayers(),
      function(p) return p:getHandcardNum() == player:getHandcardNum() and not p:isNude() end)
  end,
  on_cost = function(self, event, target, player, data)
    local list = table.filter(player.room:getAllPlayers(), function(p) return p:getHandcardNum() == player:getHandcardNum() and not p:isNude() end)
    if #list == 1 then
      event:setCostData(self, {tos = list[1]})
      return true
    else
      local to = player.room:askToChoosePlayers(player, {
        min_num = 1,
        max_num = 1,
        targets = list,
        skill_name = zishucup__buqun.name,
        cancelable = false,
        prompt = "#zishucup__buqun-choose",
      })
      event:setCostData(self, {tos = to[1]})
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local to = event:getCostData(self).tos
    local chosen = player.room:askToChooseCard(player, { target = to, flag = "he", skill_name = zishucup__buqun.name })
    to:addToPile("$zishucup__buqun", {chosen}, nil, zishucup__buqun.name)
  end,
})

zishucup__buqun:addEffect(fk.TurnEnd, {
  is_delay_effect = true,
  mute = true,
  can_trigger = function(self, event, target, player, data)
    return not player.dead and #player:getPile("$zishucup__buqun") > 0
  end,
  on_use = function(self, event, target, player, data)
    player.room:moveCardTo(player:getPile("$zishucup__buqun"), Player.Hand, player, fk.ReasonPrey, zishucup__buqun.name)
  end,
})

return zishucup__buqun
